package com.ellecity06.common.ktx

import android.annotation.SuppressLint
import android.text.format.DateFormat
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date

/**
 * @author ellecity06
 * @time 2025/3/20 20:28
 * @des
 */

fun yesterdayStr(pattern: String = "yyyy-MM-dd"): String {
    val calendar = Calendar.getInstance()
    calendar.add(Calendar.DATE, -1)
    val f = SimpleDateFormat(pattern)
    return f.format(calendar.time)
}
fun lastWeekStr(pattern: String = "yyyy-MM-dd"): String {
    val calendar = Calendar.getInstance()
    calendar.add(Calendar.DATE, -7)
    val f = SimpleDateFormat(pattern)
    return f.format(calendar.time)
}
fun lastYearStr(pattern: String = "yyyy-MM-dd"): String {
    val calendar = Calendar.getInstance()
    calendar.add(Calendar.MONTH, -1)
    val f = SimpleDateFormat(pattern)
    return f.format(calendar.time)
}

@SuppressLint("SimpleDateFormat")
fun todayStr(pattern: String = "yyyy-MM-dd"): String {
    val f = SimpleDateFormat(pattern)
    return f.format(todayDate())

}
fun Long.toDateStr(pattern: String = "yyyy-MM-dd") : String{
   return DateFormat.format(pattern, this).toString()
}
fun todayDate(): Date {
    val calendar = Calendar.getInstance()
    return calendar.time
}